
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>设计模式 · GitBook笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="chenjiebin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="JavaTest.html" />
    
    
    <link rel="prev" href="effectiveJava.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../document/kubernetes/kubernetes.html">
            
                <a href="../document/kubernetes/kubernetes.html">
            
                    
                    Kubernetes英文教程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../document/kubernetes/kubernetes.html">
            
                <a href="../document/kubernetes/kubernetes.html#concepts">
            
                    
                    Kubernetes Concepts
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="../document/kubernetes/concepts/overview.html">
            
                <a href="../document/kubernetes/concepts/overview.html">
            
                    
                    Kubernetes Overview
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2" data-path="../document/kubernetes/concepts/components.html">
            
                <a href="../document/kubernetes/concepts/components.html">
            
                    
                    Kubernetes Components
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.3" data-path="../document/kubernetes/concepts/nodes.html">
            
                <a href="../document/kubernetes/concepts/nodes.html">
            
                    
                    Kubernetes Nodes
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../document/kubernetes/kubernetes.html">
            
                <a href="../document/kubernetes/kubernetes.html#tutorial">
            
                    
                    Kubernetes Tutorial
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="../document/kubernetes/tutorial/kubernetes-basics.html">
            
                <a href="../document/kubernetes/tutorial/kubernetes-basics.html">
            
                    
                    Kubernetes Basics
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="java.html">
            
                <a href="java.html">
            
                    
                    Java基础知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="java-summary.html">
            
                <a href="java-summary.html">
            
                    
                    Java_Summary
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="java-jvm.html">
            
                <a href="java-jvm.html">
            
                    
                    Java_JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="effectiveJava.html">
            
                <a href="effectiveJava.html">
            
                    
                    effectiveJava
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.4" data-path="design-pattern.html">
            
                <a href="design-pattern.html">
            
                    
                    设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="JavaTest.html">
            
                <a href="JavaTest.html">
            
                    
                    JavaTest
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="myframe.html">
            
                <a href="myframe.html">
            
                    
                    MyFrame
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../database/database.html">
            
                <a href="../database/database.html">
            
                    
                    数据库基础知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../database/mysql.html">
            
                <a href="../database/mysql.html">
            
                    
                    MySQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../database/redis.html">
            
                <a href="../database/redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../database/kingbase.html">
            
                <a href="../database/kingbase.html">
            
                    
                    KingBase
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../database/polardb.html">
            
                <a href="../database/polardb.html">
            
                    
                    PolarDB
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../system/system.html">
            
                <a href="../system/system.html">
            
                    
                    环境配置工具
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../system/nodejs.html">
            
                <a href="../system/nodejs.html">
            
                    
                    Node.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../system/gitbook.html">
            
                <a href="../system/gitbook.html">
            
                    
                    Gitbook
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../system/linux.html">
            
                <a href="../system/linux.html">
            
                    
                    Linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../system/kylin.html">
            
                <a href="../system/kylin.html">
            
                    
                    麒麟系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../tool/tool.html">
            
                <a href="../tool/tool.html">
            
                    
                    开发工具介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../tool/docker.html">
            
                <a href="../tool/docker.html">
            
                    
                    Docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../tool/idea.html">
            
                <a href="../tool/idea.html">
            
                    
                    Idea
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../tool/maven.html">
            
                <a href="../tool/maven.html">
            
                    
                    Maven
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../tool/gradle.html">
            
                <a href="../tool/gradle.html">
            
                    
                    Gradle
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../framework/kubernate.html">
            
                <a href="../framework/kubernate.html">
            
                    
                    Kubernetes
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >设计模式</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x5206;&#x7C7B;"><b>1. </b>&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x5206;&#x7C7B;</a></li><ul><li><span class="title-icon "></span><a href="#&#x521B;&#x5EFA;&#x578B;&#x6A21;&#x5F0F;-5"><b>1.1. </b>&#x521B;&#x5EFA;&#x578B;&#x6A21;&#x5F0F; 5</a></li><li><span class="title-icon "></span><a href="#&#x7ED3;&#x6784;&#x6027;&#x6A21;&#x5F0F;-7"><b>1.2. </b>&#x7ED3;&#x6784;&#x6027;&#x6A21;&#x5F0F; 7</a></li><li><span class="title-icon "></span><a href="#&#x884C;&#x4E3A;&#x6027;&#x6A21;&#x5F0F;-11"><b>1.3. </b>&#x884C;&#x4E3A;&#x6027;&#x6A21;&#x5F0F; 11</a></li></ul><li><span class="title-icon "></span><a href="#&#x516D;&#x5927;&#x539F;&#x5219;"><b>2. </b>&#x516D;&#x5927;&#x539F;&#x5219;</a></li><li><span class="title-icon "></span><a href="#&#x5DE5;&#x5382;&#x6A21;&#x5F0F;"><b>3. </b>&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</a></li><ul><li><span class="title-icon "></span><a href="#&#x666E;&#x901A;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;"><b>3.1. </b>&#x666E;&#x901A;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#&#x591A;&#x4E2A;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;"><b>3.2. </b>&#x591A;&#x4E2A;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;"><b>3.3. </b>&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;</a></li></ul><li><span class="title-icon "></span><a href="#&#x62BD;&#x8C61;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;"><b>4. </b>&#x62BD;&#x8C61;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#&#x5355;&#x4F8B;&#x6A21;&#x5F0F;"><b>5. </b>&#x5355;&#x4F8B;&#x6A21;&#x5F0F;</a></li><ul><li><span class="title-icon "></span><a href="#&#x61D2;&#x6C49;&#x5F0F;"><b>5.1. </b>&#x61D2;&#x6C49;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#&#x52A0;&#x540C;&#x6B65;&#x9501;"><b>5.2. </b>&#x52A0;&#x540C;&#x6B65;&#x9501;</a></li><li><span class="title-icon "></span><a href="#&#x53CC;&#x91CD;&#x68C0;&#x9A8C;&#x9501;"><b>5.3. </b>&#x53CC;&#x91CD;&#x68C0;&#x9A8C;&#x9501;</a></li><li><span class="title-icon "></span><a href="#&#x5185;&#x90E8;&#x7C7B;"><b>5.4. </b>&#x5185;&#x90E8;&#x7C7B;</a></li><li><span class="title-icon "></span><a href="#&#x4F7F;&#x7528;&#x679A;&#x4E3E;"><b>5.5. </b>&#x4F7F;&#x7528;&#x679A;&#x4E3E;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5EFA;&#x9020;&#x8005;&#x6A21;&#x5F0F;"><b>6. </b>&#x5EFA;&#x9020;&#x8005;&#x6A21;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#&#x539F;&#x578B;&#x6A21;&#x5F0F;"><b>7. </b>&#x539F;&#x578B;&#x6A21;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#&#x88C5;&#x9970;&#x6A21;&#x5F0F;"><b>8. </b>&#x88C5;&#x9970;&#x6A21;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#&#x53C2;&#x8003;"><b>9. </b>&#x53C2;&#x8003;</a></li></ul></div><a href="#&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x5206;&#x7C7B;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x5206;&#x7C7B;"><a name="&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x5206;&#x7C7B;" class="anchor-navigation-ex-anchor" href="#&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x5206;&#x7C7B;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x5206;&#x7C7B;</h1>
<h2 id="&#x521B;&#x5EFA;&#x578B;&#x6A21;&#x5F0F;-5"><a name="&#x521B;&#x5EFA;&#x578B;&#x6A21;&#x5F0F;-5" class="anchor-navigation-ex-anchor" href="#&#x521B;&#x5EFA;&#x578B;&#x6A21;&#x5F0F;-5"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x521B;&#x5EFA;&#x578B;&#x6A21;&#x5F0F; 5</h2>
<ol>
<li>&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</li>
<li>&#x62BD;&#x8C61;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</li>
<li>&#x5355;&#x4F8B;&#x6A21;&#x5F0F;</li>
<li>&#x5EFA;&#x9020;&#x8005;&#x6A21;&#x5F0F;</li>
<li>&#x539F;&#x578B;&#x6A21;&#x5F0F;</li>
</ol>
<h2 id="&#x7ED3;&#x6784;&#x6027;&#x6A21;&#x5F0F;-7"><a name="&#x7ED3;&#x6784;&#x6027;&#x6A21;&#x5F0F;-7" class="anchor-navigation-ex-anchor" href="#&#x7ED3;&#x6784;&#x6027;&#x6A21;&#x5F0F;-7"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x7ED3;&#x6784;&#x6027;&#x6A21;&#x5F0F; 7</h2>
<ol>
<li>&#x9002;&#x914D;&#x5668;&#x6A21;&#x5F0F;</li>
<li>&#x88C5;&#x9970;&#x5668;&#x6A21;&#x5F0F;</li>
<li>&#x4EE3;&#x7406;&#x6A21;&#x5F0F;</li>
<li>&#x5916;&#x89C2;&#x6A21;&#x5F0F;</li>
<li>&#x6865;&#x63A5;&#x6A21;&#x5F0F;</li>
<li>&#x7EC4;&#x5408;&#x6A21;&#x5F0F;</li>
<li>&#x4EAB;&#x5143;&#x6A21;&#x5F0F;</li>
</ol>
<h2 id="&#x884C;&#x4E3A;&#x6027;&#x6A21;&#x5F0F;-11"><a name="&#x884C;&#x4E3A;&#x6027;&#x6A21;&#x5F0F;-11" class="anchor-navigation-ex-anchor" href="#&#x884C;&#x4E3A;&#x6027;&#x6A21;&#x5F0F;-11"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. &#x884C;&#x4E3A;&#x6027;&#x6A21;&#x5F0F; 11</h2>
<ol>
<li>&#x7B56;&#x7565;&#x6A21;&#x5F0F;</li>
<li>&#x6A21;&#x7248;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;</li>
<li>&#x89C2;&#x5BDF;&#x8005;&#x6A21;&#x5F0F;</li>
<li>&#x8FED;&#x4EE3;&#x5B50;&#x6A21;&#x5F0F;</li>
<li>&#x8D23;&#x4EFB;&#x94FE;&#x6A21;&#x5F0F;</li>
<li>&#x547D;&#x4EE4;&#x6A21;&#x5F0F;</li>
<li>&#x5907;&#x5FD8;&#x5F55;&#x6A21;&#x5F0F;</li>
<li>&#x72B6;&#x6001;&#x6A21;&#x5F0F;</li>
<li>&#x8BBF;&#x95EE;&#x8005;&#x6A21;&#x5F0F;</li>
<li>&#x4E2D;&#x4ECB;&#x8005;&#x6A21;&#x5F0F;</li>
<li>&#x89E3;&#x91CA;&#x5668;&#x6A21;&#x5F0F;</li>
</ol>
<h1 id="&#x516D;&#x5927;&#x539F;&#x5219;"><a name="&#x516D;&#x5927;&#x539F;&#x5219;" class="anchor-navigation-ex-anchor" href="#&#x516D;&#x5927;&#x539F;&#x5219;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x516D;&#x5927;&#x539F;&#x5219;</h1>
<ul>
<li>&#x5F00;&#x95ED;&#x539F;&#x5219;</li>
</ul>
<p>Open Close Principle</p>
<p><strong>&#x5BF9;&#x6269;&#x5C55;&#x5F00;&#x653E;&#xFF0C;&#x5BF9;&#x4FEE;&#x6539;&#x5173;&#x95ED;</strong>&#xFF0C;&#x5728;&#x7A0B;&#x5E8F;&#x62D3;&#x5C55;&#x65F6;&#xFF0C;&#x4E0D;&#x4FEE;&#x6539;&#x539F;&#x6709;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x5B9E;&#x73B0;&#x70ED;&#x62D4;&#x63D2;&#x7684;&#x6548;&#x679C;</p>
<p>&#x4E3A;&#x4E86;&#x7A0B;&#x5E8F;&#x7684;&#x6269;&#x5C55;&#x6027;&#xFF0C;&#x6613;&#x4E8E;&#x7EF4;&#x62A4;&#x548C;&#x5347;&#x7EA7;&#xFF0C;&#x4F7F;&#x7528;&#x63A5;&#x53E3;&#x548C;&#x62BD;&#x8C61;&#x7C7B;</p>
<ul>
<li>&#x91CC;&#x6C0F;&#x66FF;&#x6362;&#x539F;&#x5219;</li>
</ul>
<p>Loskov Substitution Principle&#xFF0C;LSP</p>
<p>&#x4EFB;&#x4F55;&#x57FA;&#x7C7B;&#x53EF;&#x4EE5;&#x51FA;&#x73B0;&#x7684;&#x5730;&#x65B9;&#xFF0C;&#x5B50;&#x7C7B;&#x4E00;&#x5B9A;&#x53EF;&#x4EE5;&#x51FA;&#x73B0;&#x3002;LSP&#x662F;&#x7EE7;&#x627F;&#x590D;&#x7528;&#x7684;&#x57FA;&#x77F3;</p>
<p>&#x53EA;&#x6709;&#x5F53;&#x884D;&#x751F;&#x7C7B;&#x53EF;&#x4EE5;&#x66FF;&#x6362;&#x6389;&#x57FA;&#x7C7B;&#xFF0C;&#x8F6F;&#x4EF6;&#x5355;&#x4F4D;&#x7684;&#x529F;&#x80FD;&#x4E0D;&#x53D7;&#x5230;&#x5F71;&#x54CD;&#x65F6;&#xFF0C;&#x57FA;&#x7C7B;&#x624D;&#x80FD;&#x771F;&#x6B63;&#x88AB;&#x590D;&#x7528;&#xFF0C;&#x884D;&#x751F;&#x7C7B;&#x4E5F;&#x80FD;&#x591F;&#x5728;&#x57FA;&#x7C7B;&#x57FA;&#x7840;&#x4E0A;&#x589E;&#x52A0;&#x65B0;&#x7684;&#x884C;&#x4E3A;&#x3002;&#x91CC;&#x6C0F;&#x66FF;&#x6362;&#x539F;&#x5219;&#x662F;&#x5BF9;&#x201C;&#x5F00;-&#x95ED;&#x201D;&#x539F;&#x5219;&#x7684;&#x8865;&#x5145;&#xFF0C;&#x5B9E;&#x73B0;&#x5F00;&#x95ED;&#x539F;&#x5219;&#x7684;&#x5173;&#x952E;&#x6B65;&#x9AA4;&#x5C31;&#x662F;&#x62BD;&#x8C61;&#x5316;&#x3002;&#x800C;&#x57FA;&#x7C7B;&#x4E0E;&#x5B50;&#x7C7B;&#x7684;&#x7EE7;&#x627F;&#x5173;&#x7CFB;&#x5C31;&#x662F;&#x62BD;&#x8C61;&#x5316;&#x7684;&#x5177;&#x4F53;&#x5B9E;&#x73B0;&#xFF0C;&#x6240;&#x4EE5;&#x91CC;&#x6C0F;&#x66FF;&#x6362;&#x662F;&#x5B9E;&#x73B0;&#x62BD;&#x8C61;&#x5316;&#x7684;&#x5177;&#x4F53;&#x6B65;&#x9AA4;&#x7684;&#x89C4;&#x8303;</p>
<ul>
<li>&#x4F9D;&#x8D56;&#x5012;&#x8F6C;&#x539F;&#x5219;</li>
</ul>
<p>Dependence Inversion Principle</p>
<p>&#x8FD9;&#x4E2A;&#x662F;&#x5F00;&#x95ED;&#x539F;&#x5219;&#x7684;&#x57FA;&#x7840;&#xFF0C;&#x5177;&#x4F53;&#x5185;&#x5BB9;&#xFF1A;&#x771F;&#x5BF9;&#x63A5;&#x53E3;&#x7F16;&#x7A0B;&#xFF0C;&#x4F9D;&#x8D56;&#x4E8E;&#x62BD;&#x8C61;&#x800C;&#x4E0D;&#x4F9D;&#x8D56;&#x4E8E;&#x5177;&#x4F53;</p>
<ul>
<li>&#x63A5;&#x53E3;&#x9694;&#x79BB;&#x539F;&#x5219;</li>
</ul>
<p>Interface Segregation Principle</p>
<p>&#x4F7F;&#x7528;&#x591A;&#x4E2A;&#x9694;&#x79BB;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x6BD4;&#x4F7F;&#x7528;&#x5355;&#x4E2A;&#x63A5;&#x53E3;&#x597D;&#x3002;&#x964D;&#x4F4E;&#x4F9D;&#x8D56;&#xFF0C;&#x964D;&#x4F4E;&#x8026;&#x5408;</p>
<ul>
<li>&#x8FEA;&#x7C73;&#x7279;&#x6CD5;&#x5219;</li>
</ul>
<p>Demeter Principle</p>
<p>&#x4E00;&#x4E2A;&#x5B9E;&#x4F53;&#x5E94;&#x5F53;&#x5C3D;&#x91CF;&#x5C11;&#x7684;&#x4E0E;&#x5176;&#x4ED6;&#x5B9E;&#x4F53;&#x4E4B;&#x95F4;&#x53D1;&#x751F;&#x76F8;&#x4E92;&#x4F5C;&#x7528;&#xFF0C;&#x662F;&#x7684;&#x7CFB;&#x7EDF;&#x529F;&#x80FD;&#x6A21;&#x5757;&#x76F8;&#x5BF9;&#x72EC;&#x7ACB;</p>
<ul>
<li>&#x5408;&#x6210;&#x590D;&#x7528;&#x539F;&#x5219;</li>
</ul>
<p>Composite Reuse Principle</p>
<p>&#x5C3D;&#x91CF;&#x4F7F;&#x7528;&#x5408;&#x6210;/&#x805A;&#x5408;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x4F7F;&#x7528;&#x7EE7;&#x627F;</p>
<p><img src="../images/design%20pattern.jpg" alt="&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x5173;&#x7CFB;&#x56FE;"></p>
<h1 id="&#x5DE5;&#x5382;&#x6A21;&#x5F0F;"><a name="&#x5DE5;&#x5382;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x5DE5;&#x5382;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x5DE5;&#x5382;&#x6A21;&#x5F0F;</h1>
<p>Factory Method</p>
<p>&#x5DE5;&#x5382;&#x6A21;&#x5F0F;&#x9002;&#x7528;&#x4E8E;&#x521B;&#x5EFA;&#x5927;&#x91CF;&#x7684;&#x4EA7;&#x54C1;&#x5B9E;&#x4F8B;&#xFF0C;&#x5E76;&#x4E14;&#x5177;&#x6709;&#x5171;&#x540C;&#x7684;&#x63A5;&#x53E3;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;&#x8FDB;&#x884C;&#x521B;&#x5EFA;</p>
<p>&#x666E;&#x901A;&#x5DE5;&#x5382;&#x53C2;&#x6570;&#x5BB9;&#x6613;&#x51FA;&#x9519;&#xFF0C;&#x4E0D;&#x80FD;&#x6B63;&#x786E;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#xFF0C;&#x9759;&#x6001;&#x5DE5;&#x5382;&#x76F8;&#x6BD4;&#x591A;&#x65B9;&#x6CD5;&#x5DE5;&#x5382;&#x4E0D;&#x9700;&#x8981;&#x521B;&#x5EFA;&#x5B9E;&#x4F8B;&#xFF0C;&#x56E0;&#x6B64;&#x591A;&#x4F7F;&#x7528;&#x9759;&#x6001;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</p>
<h2 id="&#x666E;&#x901A;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;"><a name="&#x666E;&#x901A;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x666E;&#x901A;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>3.1. &#x666E;&#x901A;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</h2>
<p>&#x7B80;&#x5386;&#x4E00;&#x4E2A;&#x5DE5;&#x5382;&#x7C7B;GeneralFactory&#xFF0C;&#x5BF9;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;Sender&#x7684;&#x7C7B;MailSender&#xFF0C;SmsSender&#x8FDB;&#x884C;&#x5B9E;&#x4F8B;&#x7684;&#x521B;&#x5EFA;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">interface</span> <span class="token class-name">Sender</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">send</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">MailSender</span> <span class="token keyword">implements</span> <span class="token class-name">Sender</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">send</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;this is mail Sender!&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">SmsSender</span> <span class="token keyword">implements</span> <span class="token class-name">Sender</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">send</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;this is sms Sender!&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Factory</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token class-name">Sender</span> <span class="token function">produce</span><span class="token punctuation">(</span><span class="token class-name">String</span> type<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token string">&quot;mail&quot;</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>type<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">MailSender</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token string">&quot;sms&quot;</span><span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span>type<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">SmsSender</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;type is null.&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword">return</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Factory</span> factory <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Factory</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Sender</span> sender <span class="token operator">=</span> factory<span class="token punctuation">.</span><span class="token function">produce</span><span class="token punctuation">(</span><span class="token string">&quot;sms&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        sender<span class="token punctuation">.</span><span class="token function">send</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="&#x591A;&#x4E2A;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;"><a name="&#x591A;&#x4E2A;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x591A;&#x4E2A;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>3.2. &#x591A;&#x4E2A;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;</h2>
<p>&#x8BE5;&#x6A21;&#x5F0F;&#x662F;&#x5BF9;&#x666E;&#x901A;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;&#x7684;&#x6539;&#x8FDB;&#xFF0C;&#x5728;&#x666E;&#x901A;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;&#x9519;&#x8BEF;&#x7684;&#x53C2;&#x6570;&#x4F1A;&#x5BFC;&#x81F4;&#x65E0;&#x6CD5;&#x6B63;&#x786E;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;</p>
<p>&#x591A;&#x4E2A;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;&#x662F;&#x63D0;&#x4F9B;&#x591A;&#x4E2A;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#xFF0C;&#x5206;&#x522B;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Factory</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token class-name">Sender</span> <span class="token function">produceMail</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">MailSender</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token class-name">Sender</span> <span class="token function">produceSms</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">SmsSender</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Factory</span> factory <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Factory</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Sender</span> sender <span class="token operator">=</span> factory<span class="token punctuation">.</span><span class="token function">produceMail</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        sender<span class="token punctuation">.</span><span class="token function">send</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;"><a name="&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>3.3. &#x9759;&#x6001;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;</h2>
<p>&#x5C06;&#x4E0A;&#x9762;&#x7684;&#x591A;&#x4E2A;&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;&#x91CC;&#x65B9;&#x6CD5;&#x7F6E;&#x4E3A;&#x9759;&#x6001;&#x7684;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x521B;&#x5EFA;&#x5DE5;&#x5382;&#x7C7B;&#x5B9E;&#x4F8B;&#xFF0C;&#x5DE5;&#x5382;&#x7C7B;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x5373;&#x53EF;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Factory</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Sender</span> <span class="token function">produceMail</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">MailSender</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Sender</span> <span class="token function">produceSms</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">SmsSender</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Sender</span> sender <span class="token operator">=</span> <span class="token class-name">Factory</span><span class="token punctuation">.</span><span class="token function">produceMail</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        sender<span class="token punctuation">.</span><span class="token function">send</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h1 id="&#x62BD;&#x8C61;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;"><a name="&#x62BD;&#x8C61;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x62BD;&#x8C61;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>4. &#x62BD;&#x8C61;&#x5DE5;&#x5382;&#x6A21;&#x5F0F;</h1>
<p>&#x5DE5;&#x5382;&#x65B9;&#x6CD5;&#x6A21;&#x5F0F;&#x5B58;&#x5728;&#x7684;&#x95EE;&#x9898;&#xFF1A;&#x7C7B;&#x7684;&#x521B;&#x5EFA;&#x4F9D;&#x8D56;&#x5DE5;&#x5382;&#x7C7B;&#xFF0C;&#x7A0B;&#x5E8F;&#x8FDB;&#x884C;&#x6269;&#x5C55;&#x65F6;&#xFF0C;&#x5C31;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x5DE5;&#x5382;&#x7C7B;&#xFF0C;&#x8FDD;&#x80CC;&#x4E86;&#x95ED;&#x5305;&#x539F;&#x5219;</p>
<p>&#x56E0;&#x6B64;&#x5BF9;&#x5DE5;&#x5382;&#x7C7B;&#x8FDB;&#x884C;&#x62BD;&#x8C61;&#xFF0C;&#x589E;&#x52A0;&#x65B0;&#x7684;&#x529F;&#x80FD;&#x65F6;&#xFF0C;&#x76F4;&#x63A5;&#x589E;&#x52A0;&#x65B0;&#x7684;&#x5DE5;&#x5382;&#x7C7B;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x4E4B;&#x524D;&#x7684;&#x4EE3;&#x7801;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">interface</span> <span class="token class-name">Provider</span><span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token class-name">Sender</span> <span class="token function">produce</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">SendMailFactory</span> <span class="token keyword">implements</span> <span class="token class-name">Provider</span><span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">Sender</span> <span class="token function">produce</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">MailSender</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">SendSmsFactory</span> <span class="token keyword">implements</span> <span class="token class-name">Provider</span><span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">Sender</span> <span class="token function">produce</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">SmsSender</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">SendMailFactory</span> factory <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SendMailFactory</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Sender</span> sender <span class="token operator">=</span> factory<span class="token punctuation">.</span><span class="token function">produce</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        sender<span class="token punctuation">.</span><span class="token function">send</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h1 id="&#x5355;&#x4F8B;&#x6A21;&#x5F0F;"><a name="&#x5355;&#x4F8B;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x5355;&#x4F8B;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>5. &#x5355;&#x4F8B;&#x6A21;&#x5F0F;</h1>
<p>&#x5355;&#x4F8B;&#x6A21;&#x5F0F;&#x662F;&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x4E2D;&#x6700;&#x5E38;&#x7528;&#x4E5F;&#x6700;&#x5E38;&#x89C1;&#x7684;&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#xFF0C;&#x4FDD;&#x8BC1;&#x4E86;&#x5728;&#x7A0B;&#x5E8F;&#x4E2D;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x5B58;&#x5728;&#x5E76;&#x4E14;&#x53EF;&#x4EE5;&#x5168;&#x5C40;&#x8BBF;&#x95EE;</p>
<blockquote>
<p>&#x6A21;&#x5F0F;&#x7279;&#x70B9;</p>
</blockquote>
<ul>
<li>&#x5BF9;&#x4E8E;&#x4E00;&#x4E9B;&#x521B;&#x5EFA;&#x9891;&#x7E41;&#x7684;&#x7C7B;&#x7684;&#x6BD4;&#x8F83;&#x5927;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x51CF;&#x5C11;&#x5F88;&#x5927;&#x7684;&#x7CFB;&#x7EDF;&#x5F00;&#x9500;</li>
<li>&#x7701;&#x53BB;&#x4E86;new&#x64CD;&#x4F5C;&#x7B26;&#xFF0C;&#x964D;&#x4F4E;&#x4E86;&#x7CFB;&#x7EDF;&#x5185;&#x5B58;&#x7684;&#x4F7F;&#x7528;&#x9891;&#x7387;&#xFF0C;&#x51CF;&#x8F7B;GC&#x538B;&#x529B;</li>
<li>&#x6709;&#x4E9B;&#x7C7B;&#x63A7;&#x5236;&#x4EA4;&#x6613;&#x6D41;&#x7A0B;&#xFF0C;&#x521B;&#x5EFA;&#x591A;&#x4E2A;&#x4F1A;&#x4F7F;&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#x51FA;&#x9519;</li>
</ul>
<blockquote>
<p>&#x4F7F;&#x7528;&#x573A;&#x666F;</p>
</blockquote>
<ul>
<li>&#x5E94;&#x7528;&#x4E2D;&#x67D0;&#x4E2A;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x9700;&#x8981;&#x9891;&#x7E41;&#x7684;&#x88AB;&#x8BBF;&#x95EE;</li>
<li>&#x5E94;&#x7528;&#x4E2D;&#x6BCF;&#x6B21;&#x542F;&#x52A8;&#x53EA;&#x4F1A;&#x5B58;&#x5728;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#xFF0C;&#x5982;&#x8D26;&#x53F7;&#x7CFB;&#x7EDF;&#xFF0C;&#x6570;&#x636E;&#x5E93;&#x7CFB;&#x7EDF;</li>
</ul>
<h2 id="&#x61D2;&#x6C49;&#x5F0F;"><a name="&#x61D2;&#x6C49;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x61D2;&#x6C49;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1. &#x61D2;&#x6C49;&#x5F0F;</h2>
<p>&#x4F18;&#x70B9;&#xFF1A;&#x5EF6;&#x8FDF;&#x52A0;&#x8F7D;&#xFF08;&#x9700;&#x8981;&#x7684;&#x65F6;&#x5019;&#x624D;&#x53BB;&#x52A0;&#x8F7D;&#xFF09;</p>
<p>&#x7F3A;&#x70B9;&#xFF1A;&#x7EBF;&#x7A0B;&#x4E0D;&#x5B89;&#x5168;&#xFF0C;&#x5728;&#x591A;&#x7EBF;&#x7A0B;&#x4E2D;&#x5F88;&#x5BB9;&#x6613;&#x51FA;&#x73B0;&#x4E0D;&#x540C;&#x6B65;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x6BD4;&#x5982;&#x6570;&#x636E;&#x5E93;&#x5BF9;&#x8C61;&#x9891;&#x7E41;&#x8BFB;&#x5199;&#x64CD;&#x4F5C;&#x65F6;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Singleton</span> <span class="token punctuation">{</span>
    <span class="token comment">// &#x6301;&#x6709;&#x79C1;&#x6709;&#x9759;&#x6001;&#x5B9E;&#x4F8B;&#xFF0C;&#x9632;&#x6B62;&#x88AB;&#x5F15;&#x7528;&#xFF0C;&#x6B64;&#x5904;&#x8D4B;&#x503C;null&#xFF0C;&#x5B9E;&#x73B0;&#x5EF6;&#x8FDF;&#x52A0;&#x8F7D;</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> instance <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token comment">// &#x6301;&#x6709;&#x79C1;&#x6709;&#x6784;&#x9020;&#x65B9;&#x6CD5;&#xFF0C;&#x9632;&#x6B62;&#x88AB;&#x5B9E;&#x4F8B;&#x5316;</span>
    <span class="token keyword">private</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>instance <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> instance<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="&#x52A0;&#x540C;&#x6B65;&#x9501;"><a name="&#x52A0;&#x540C;&#x6B65;&#x9501;" class="anchor-navigation-ex-anchor" href="#&#x52A0;&#x540C;&#x6B65;&#x9501;"><i class="fa fa-link" aria-hidden="true"></i></a>5.2. &#x52A0;&#x540C;&#x6B65;&#x9501;</h2>
<p>&#x4F18;&#x70B9;&#xFF1A;&#x89E3;&#x51B3;&#x4E86;&#x7EBF;&#x7A0B;&#x4E0D;&#x5B89;&#x5168;&#x7684;&#x95EE;&#x9898;</p>
<p>&#x7F3A;&#x70B9;&#xFF1A;&#x6548;&#x7387;&#x4F4E;&#xFF0C;&#x6BCF;&#x6B21;&#x8C03;&#x7528;&#x5B9E;&#x4F8B;&#x90FD;&#x8981;&#x5224;&#x65AD;&#x540C;&#x6B65;&#x9501;</p>
<pre class="language-"><code class="lang-java"><span class="token comment">// &#x65B9;&#x6CD5;&#x52A0;synchronized</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Singleton</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> instance <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">synchronized</span> <span class="token class-name">Singleton</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>instance <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> instance<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token comment">// &#x5185;&#x90E8;&#x52A0;synchronized&#xFF0C;&#x4F46;&#x662F;&#x6BCF;&#x6B21;&#x8C03;&#x7528;&#x5B9E;&#x4F8B;&#x90FD;&#x4F1A;&#x52A0;&#x8F7D;</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Singleton</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> instance <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">synchronized</span> <span class="token punctuation">(</span><span class="token class-name">Singleton</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>instance <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> instance<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="&#x53CC;&#x91CD;&#x68C0;&#x9A8C;&#x9501;"><a name="&#x53CC;&#x91CD;&#x68C0;&#x9A8C;&#x9501;" class="anchor-navigation-ex-anchor" href="#&#x53CC;&#x91CD;&#x68C0;&#x9A8C;&#x9501;"><i class="fa fa-link" aria-hidden="true"></i></a>5.3. &#x53CC;&#x91CD;&#x68C0;&#x9A8C;&#x9501;</h2>
<p>&#x4F18;&#x70B9;&#xFF1A;&#x5E76;&#x53D1;&#x91CF;&#x4E0D;&#x591A;&#xFF0C;&#x5B89;&#x5168;&#x6027;&#x4E0D;&#x9AD8;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x6216;&#x8BB8;&#x80FD;&#x5F88;&#x5B8C;&#x7F8E;&#x8FD0;&#x884C;&#x5355;&#x4F8B;&#x6A21;&#x5F0F;</p>
<p>&#x7F3A;&#x70B9;&#xFF1A;&#x4E0D;&#x540C;&#x5E73;&#x53F0;&#x7F16;&#x8BD1;&#x8FC7;&#x7A0B;&#x4E2D;&#x53EF;&#x80FD;&#x5B58;&#x5728;&#x4E25;&#x91CD;&#x5B89;&#x5168;&#x9690;&#x60A3;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Singleton</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> instance <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
    <span class="token keyword">private</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">Singleton</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>instance <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token comment">// &#x53EA;&#x5728;&#x7B2C;&#x4E00;&#x6B21;&#x521D;&#x59CB;&#x5316;&#x7684;&#x65F6;&#x5019;&#x52A0;&#x9501;</span>
            <span class="token keyword">synchronized</span> <span class="token punctuation">(</span><span class="token class-name">Singleton</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>instance <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                    instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> instance<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5982;&#x679C;synchronized&#x5185;&#x90E8;&#x7684;instance&#x975E;&#x7A7A;&#x5224;&#x65AD;&#x53BB;&#x6389;&#x9020;&#x6210;&#x7684;&#x95EE;&#x9898;&#xFF1A;</p>
<p>&#x4E24;&#x4E2A;&#x7EBF;&#x7A0B;&#x540C;&#x65F6;&#x8FDB;&#x5165;&#x7B2C;&#x4E00;&#x5C42;instance&#x5224;&#x65AD;&#xFF0C;&#x4E00;&#x4E2A;&#x52A0;&#x9501;&#x6267;&#x884C;&#x540E;&#x91CA;&#x653E;&#x9501;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x6267;&#x884C;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x62A5;&#x9519;</p>
<pre class="language-"><code class="lang-java">instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Singleton</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x5728;JVM&#x7F16;&#x8BD1;&#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#x4F1A;&#x51FA;&#x73B0;&#x6307;&#x4EE4;&#x91CD;&#x6392;&#x7684;&#x4F18;&#x5316;&#x8FC7;&#x7A0B;&#xFF0C;&#x4F1A;&#x5BFC;&#x81F4;&#x5F53;instance&#x5B9E;&#x9645;&#x4E0A;&#x8FD8;&#x6CA1;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x5C31;&#x53EF;&#x80FD;&#x88AB;&#x5206;&#x914D;&#x4E86;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4; instance!=null &#x4F46;&#x662F;&#x53C8;&#x6CA1;&#x521D;&#x59CB;&#x5316;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x4F1A;&#x5BFC;&#x81F4;&#x8FD4;&#x56DE;&#x7684;instance&#x4E0D;&#x5B8C;&#x6574;</p>
<h2 id="&#x5185;&#x90E8;&#x7C7B;"><a name="&#x5185;&#x90E8;&#x7C7B;" class="anchor-navigation-ex-anchor" href="#&#x5185;&#x90E8;&#x7C7B;"><i class="fa fa-link" aria-hidden="true"></i></a>5.4. &#x5185;&#x90E8;&#x7C7B;</h2>
<p>&#x4F18;&#x70B9;&#xFF1A;&#x5EF6;&#x8FDF;&#x52A0;&#x8F7D;&#xFF0C;&#x7EBF;&#x7A0B;&#x5B89;&#x5168;&#xFF08;java&#x4E2D;class&#x52A0;&#x8F7D;&#x65F6;&#x4E92;&#x65A5;&#xFF09;&#xFF0C;&#x51CF;&#x5C11;&#x5185;&#x5B58;&#x6D88;&#x8017;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SingletonInner</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">class</span> <span class="token class-name">SingletonHolder</span><span class="token punctuation">{</span>
        <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token class-name">SingletonInner</span> instance <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">SingletonInner</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">private</span> <span class="token class-name">SingletonInner</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token class-name">SingletonInner</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token class-name">SingletonInner</span><span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="&#x4F7F;&#x7528;&#x679A;&#x4E3E;"><a name="&#x4F7F;&#x7528;&#x679A;&#x4E3E;" class="anchor-navigation-ex-anchor" href="#&#x4F7F;&#x7528;&#x679A;&#x4E3E;"><i class="fa fa-link" aria-hidden="true"></i></a>5.5. &#x4F7F;&#x7528;&#x679A;&#x4E3E;</h2>
<pre class="language-"><code class="lang-java"><span class="token keyword">public</span> <span class="token keyword">enum</span>  <span class="token class-name">SingletonEnum</span> <span class="token punctuation">{</span>
    <span class="token constant">INSTANCE</span><span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x6267;&#x884C;&#x5355;&#x4F8B;&#x6A21;&#x5F0F;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">SingletonEnum</span><span class="token punctuation">.</span><span class="token constant">INSTANCE</span><span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h1 id="&#x5EFA;&#x9020;&#x8005;&#x6A21;&#x5F0F;"><a name="&#x5EFA;&#x9020;&#x8005;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x5EFA;&#x9020;&#x8005;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>6. &#x5EFA;&#x9020;&#x8005;&#x6A21;&#x5F0F;</h1>
<p>&#x521B;&#x5EFA;&#x8005;&#x6A21;&#x5F0F;&#x5C06;&#x5404;&#x79CD;&#x4EA7;&#x54C1;&#x96C6;&#x4E2D;&#x8D77;&#x6765;&#x8FDB;&#x884C;&#x7BA1;&#x7406;&#xFF0C;&#x521B;&#x5EFA;&#x590D;&#x5408;&#x5BF9;&#x8C61;&#xFF1A;&#x67D0;&#x4E2A;&#x5BF9;&#x8C61;&#x5177;&#x6709;&#x4E0D;&#x540C;&#x7684;&#x5C5E;&#x6027;</p>
<p>&#x5DE5;&#x5382;&#x6A21;&#x5F0F;&#x5173;&#x6CE8;&#x7684;&#x662F;&#x521B;&#x5EFA;&#x5355;&#x4E2A;&#x4EA7;&#x54C1;&#xFF0C;&#x521B;&#x5EFA;&#x8005;&#x6A21;&#x5F0F;&#x5173;&#x6CE8;&#x521B;&#x5EFA;&#x590D;&#x5408;&#x5BF9;&#x8C61;&#xFF0C;&#x591A;&#x4E2A;&#x90E8;&#x5206;</p>
<pre class="language-"><code class="lang-java"><span class="token keyword">class</span> <span class="token class-name">Builder</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Sender</span><span class="token punctuation">&gt;</span></span> list <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Sender</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">produceMainSender</span><span class="token punctuation">(</span><span class="token keyword">int</span> count<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> count<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">MailSender</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">produceSmsSender</span><span class="token punctuation">(</span><span class="token keyword">int</span> count<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> count<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            list<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">SmsSender</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token class-name">Builder</span> builder <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Builder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        builder<span class="token punctuation">.</span><span class="token function">produceMainSender</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h1 id="&#x539F;&#x578B;&#x6A21;&#x5F0F;"><a name="&#x539F;&#x578B;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x539F;&#x578B;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>7. &#x539F;&#x578B;&#x6A21;&#x5F0F;</h1>
<p>&#x539F;&#x578B;&#x6A21;&#x5F0F;&#x867D;&#x7136;&#x662F;&#x521B;&#x5EFA;&#x578B;&#x7684;&#x6A21;&#x5F0F;&#xFF0C;&#x4F46;&#x662F;&#x4E0E;&#x5DE5;&#x7A0B;&#x6A21;&#x5F0F;&#x6CA1;&#x6709;&#x5173;&#x7CFB;</p>
<p>&#x6539;&#x6A21;&#x5F0F;&#x7684;&#x601D;&#x60F3;&#x5C31;&#x662F;&#x5C06;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x4F5C;&#x4E3A;&#x539F;&#x578B;&#xFF0C;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x590D;&#x5236;&#x3001;&#x514B;&#x9686;&#xFF0C;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x548C;&#x5143;&#x5BF9;&#x8C61;&#x7C7B;&#x4F3C;&#x7684;&#x65B0;&#x5BF9;&#x8C61;</p>
<h1 id="&#x88C5;&#x9970;&#x6A21;&#x5F0F;"><a name="&#x88C5;&#x9970;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#&#x88C5;&#x9970;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>8. &#x88C5;&#x9970;&#x6A21;&#x5F0F;</h1>
<h1 id="&#x53C2;&#x8003;"><a name="&#x53C2;&#x8003;" class="anchor-navigation-ex-anchor" href="#&#x53C2;&#x8003;"><i class="fa fa-link" aria-hidden="true"></i></a>9. &#x53C2;&#x8003;</h1>
<p><a href="https://blog.csdn.net/chzkal/article/details/89471423" target="_blank">&#x6700;&#x901A;&#x4FD7;&#x6613;&#x61C2;&#x7684;java &#x516D;&#x5927;&#x539F;&#x5219;--&#x4EE3;&#x7801;&#x89E3;&#x6790;_CHZKAL&#x7684;&#x535A;&#x5BA2;-CSDN&#x535A;&#x5BA2;</a></p>
<p><a href="https://blog.csdn.net/sugar_no1/article/details/88317950" target="_blank">Java&#x4E2D;&#x5E38;&#x7528;&#x7684;&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;_Superme-CSDN&#x535A;&#x5BA2;_java &#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;</a></p>
<p><a href="https://blog.csdn.net/chzkal/article/details/89471423" target="_blank">&#x6700;&#x901A;&#x4FD7;&#x6613;&#x61C2;&#x7684;java &#x516D;&#x5927;&#x539F;&#x5219;--&#x4EE3;&#x7801;&#x89E3;&#x6790;_CHZKAL&#x7684;&#x535A;&#x5BA2;-CSDN&#x535A;&#x5BA2;</a></p>
<p><a href="https://www.cnblogs.com/yanggb/p/10922079.html#:~:text=&#x5355;&#x4E00;&#x804C;&#x8D23;&#x539F;&#x5219;&#x5B9A;&#x4E49;&#x662F;&#xFF1A;&#x4E0D;&#x8981;&#x5B58;&#x5728;&#x591A;&#x4E8E;&#x4E00;&#x4E2A;&#x5BFC;&#x81F4;&#x7C7B;&#x53D8;&#x66F4;&#x7684;&#x539F;&#x56E0;&#x3002; &#x901A;&#x4FD7;&#x5730;&#x8BF4;&#xFF0C;&#x5373;&#x4E00;&#x4E2A;&#x7C7B;&#x53EA;&#x8D1F;&#x8D23;&#x4E00;&#x9879;&#x804C;&#x8D23;&#x3002; &#x6709;&#x4E00;&#x4E2A;&#x7C7B;T&#x8D1F;&#x8D23;&#x4E24;&#x4E2A;&#x4E0D;&#x540C;&#x7684;&#x804C;&#x8D23;&#xFF1A;&#x804C;&#x8D23;P1&#x548C;&#x804C;&#x8D23;P2&#x3002; &#x5F53;&#x56E0;&#x4E3A;&#x804C;&#x8D23;P1&#x7684;&#x9700;&#x6C42;&#x53D1;&#x751F;&#x6539;&#x53D8;&#x800C;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x7C7B;T&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x6709;&#x53EF;&#x80FD;&#x4F1A;&#x5BFC;&#x81F4;&#x539F;&#x672C;&#x8FD0;&#x884C;&#x6B63;&#x5E38;&#x7684;&#x804C;&#x8D23;P2&#x529F;&#x80FD;&#x53D1;&#x751F;&#x6545;&#x969C;&#x3002;,&#x9075;&#x5FAA;&#x5355;&#x4E00;&#x804C;&#x8D23;&#x539F;&#x5219;&#xFF0C;&#x5206;&#x522B;&#x5EFA;&#x7ACB;&#x4E24;&#x4E2A;&#x7C7B;T1&#x3001;T2&#xFF0C;&#x4F7F;T1&#x5B8C;&#x6210;&#x804C;&#x8D23;P1&#x529F;&#x80FD;&#xFF0C;T2&#x5B8C;&#x6210;&#x804C;&#x8D23;P2&#x529F;&#x80FD;&#x3002; &#x8FD9;&#x6837;&#xFF0C;&#x5F53;&#x4FEE;&#x6539;&#x7C7B;T1&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E0D;&#x4F1A;&#x4F7F;&#x804C;&#x8D23;P2&#x53D1;&#x751F;&#x6545;&#x969C;&#x98CE;&#x9669;&#x3002; &#x540C;&#x7406;&#xFF0C;&#x5F53;&#x4FEE;&#x6539;T2&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x4F7F;&#x804C;&#x8D23;P1&#x53D1;&#x751F;&#x6545;&#x969C;&#x98CE;&#x9669;&#x3002; &#x8BF4;&#x5230;&#x5355;&#x4E00;&#x804C;&#x8D23;&#x539F;&#x5219;&#xFF0C;&#x5F88;&#x591A;&#x4EBA;&#x90FD;&#x4F1A;&#x4E0D;&#x5C51;&#x4E00;&#x987E;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x592A;&#x7B80;&#x5355;&#x4E86;&#x3002; &#x7A0D;&#x6709;&#x7ECF;&#x9A8C;&#x7684;&#x7A0B;&#x5E8F;&#x5458;&#x5373;&#x4F7F;&#x4ECE;&#x6765;&#x6CA1;&#x6709;&#x8BFB;&#x8FC7;&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#xFF0C;&#x4ECE;&#x6765;&#x6CA1;&#x6709;&#x542C;&#x8BF4;&#x8FC7;&#x5355;&#x4E00;&#x804C;&#x8D23;&#x539F;&#x5219;&#xFF0C;&#x5728;&#x8BBE;&#x8BA1;&#x8F6F;&#x4EF6;&#x7684;&#x65F6;&#x5019;&#x4E5F;&#x4F1A;&#x81EA;&#x89C9;&#x9075;&#x5B88;&#x8FD9;&#x4E2A;&#x91CD;&#x8981;&#x539F;&#x5219;&#xFF0C;&#x56E0;&#x4E3A;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x5E38;&#x8BC6;&#x3002;" target="_blank">&#x8BBE;&#x8BA1;&#x6A21;&#x5F0F;&#x516D;&#x5927;&#x539F;&#x5219;&#xFF08;&#x4E00;&#xFF09;&#xFF1A;&#x5355;&#x4E00;&#x804C;&#x8D23;&#x539F;&#x5219; - yanggb - &#x535A;&#x5BA2;&#x56ED; (cnblogs.com)</a></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="effectiveJava.html" class="navigation navigation-prev " aria-label="Previous page: effectiveJava">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="JavaTest.html" class="navigation navigation-next " aria-label="Next page: JavaTest">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"设计模式","level":"1.3.4","depth":2,"next":{"title":"JavaTest","level":"1.3.5","depth":2,"path":"markdown/java/JavaTest.md","ref":"markdown/java/JavaTest.md","articles":[]},"previous":{"title":"effectiveJava","level":"1.3.3","depth":2,"path":"markdown/java/effectiveJava.md","ref":"markdown/java/effectiveJava.md","articles":[]},"dir":"ltr"},"config":{"plugins":["theme-default","prism","-highlight","search-pro","-search","-lunr","expandable-chapters-small","splitter","-sharing","anchor-navigation-ex","code"],"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"},"pluginsConfig":{"prism":{},"search-pro":{},"expandable-chapters-small":{},"splitter":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"showLevel":false,"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}}},"theme":"default","author":"chenjiebin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pluginConfig":{"prism":{"css":["prismjs/themes/prism-solarizedlight.css"]},"anchor-navigation-ex":{"showLevel":true},"theme-default":{"toggleMenu":false}},"variables":{},"title":"GitBook笔记","gitbook":"*","description":"学习笔记，包含前后端基础知识及框架的学习笔记"},"file":{"path":"markdown/java/design-pattern.md","mtime":"2023-11-19T13:43:04.099Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2024-02-28T09:32:04.838Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

